<template>
    <div>
       <h1>医生添加</h1>
       <table class="table table-bordered">
        <tbody>
            <tr>
                <td align="right">医生名称</td>
                <td>
                    <input type="text" v-model="query.doctorName"/>
                </td>
            </tr>
            <tr>
                <td align="right">医生图片</td>
                <td>
                    <input type="file" @change="Img"/>
                    <img :src="query.doctorImg" width="100px" height="140px" v-if="query.doctorImg!=''"/>
                </td>
            </tr>
            <tr>
                <td align="right">科室名称</td>
                <td>
                    <select v-model="query.departmentName">
                        <option value="">请选择</option>
                        <option :value="item.departmentName" v-for="item in list">{{ item.departmentName }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">学历</td>
                <td>
                    <select v-model="query.edubackground">
                        <option value="">请选择</option>
                        <option value="大专">大专</option>
                        <option value="本科">本科</option>
                        <option value="研究生">研究生</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">职称</td>
                <td>
                    <select v-model="query.positionName">
                        <option value="">请选择</option>
                        <option value="主任">主任</option>
                        <option value="主治医师">主治医师</option>
                        <option value="护士">护士</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">第一职业医院</td>
                <td>
                    <input type="text" v-model="query.hospitalName"/>
                </td>
            </tr>
            <tr>
                <td align="right">是否开通账号</td>
                <td>
                    <input type="radio" name="isnull" :value="0" v-model="query.isNoRome"/>是
                    <input type="radio" name="isnull" :value="1" v-model="query.isNoRome"/>否
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="添加" class="btn btn-success" @click="ok"/>
                </td>
            </tr>
        </tbody>
       </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,reactive,onMounted } from 'vue';
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';
//接收值
const route=useRoute();
//跳转页面
const router=useRouter();

let list:any=ref([])


onMounted(()=>{
  showlist();
})
//显示科室信息
const showlist=()=>
{
   axios
   ({
      url:'/api/Department/ShowDepartment',
      method:'get'
   })
   .then(res=>{
    list.value=res.data;
   })
   .catch(err=>{

   })
}


const Img=(e:any)=>
{
    console.log(e);
    let t=e.target.files[0];
    let obj=new FormData();
    obj.append('file',t);
    axios
    ({
        url:'/api/Doctor/Img',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data=="不是图片")
        {
            alert("您上传的不是图片");
            return;
        }
        if(res.data=="图片大小大于2M")
        {
            alert("图片大小不能大于2M");
            return;
        }
        query.doctorImg=res.data;
    })
    .catch(err=>{

    })
}


let query:any=reactive
({
  "doctorName": "",
  "doctorImg": "",
  "departmentName": "",
  "edubackground": "",
  "positionName": "",
  "hospitalName": "",
  "isNoRome": 0
})

const ok=()=>
{
    if(query.doctorName=="")
    {
        alert("医生名称不能为空");
        return;
    }
    if(query.doctorImg=="")
    {
        alert("图片不能为空");
        return;
    }
    if(query.departmentName=="")
    {
        alert("科室不能为空");
        return;
    }
    if(query.edubackground=="")
    {
        alert("学历不能为空");
        return;
    }
    if(query.positionName=="")
    {
        alert("职称不能为空");
        return;
    }
    axios
    ({
        url:'/api/Doctor/DoctorAdd',
        method:'post',
        data:query
    })
    .then(res=>{
        if(res.data>0)
        {
            alert("添加成功");
            router.push('/doctorList');
            return;
        }
        else
        {
            alert("添加失败");
            return;
        }
    })
    .catch(err=>{

    })
}


</script>

<style scoped>

</style>